<template>
  <div class="cart-list-item">
    <check-button class="button" @click.native="checkClick" :isActive="cartList.checked"></check-button>
    <div class="img"><img :src="cartList.image" alt=""></div>
    <div class="item-info">
      <div class="title">{{cartList.title}}</div>
      <div class="desc">{{cartList.desc}}</div>
      <div class="price-info">
        <span>{{cartList.price | priceType}}</span>
        <span>
          <button @click="decreate" :disabled="disabled">-</button>
          {{cartList.count}}
          <button @click="increate">+</button>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import CheckButton from '@/components/common/checkbutton/CheckButton'

export default {
  components: {
    CheckButton
  },
  props: {
    cartList: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    disabled() {
      return this.cartList.count <= 1
    }
  },
  filters: {
    priceType(price) {
      return '￥' + parseFloat(price).toFixed(2)
    }
  },
  methods: {
    checkClick() {
      this.cartList.checked = !this.cartList.checked
    },
    decreate() {
      this.cartList.count --
    },
    increate() {
      this.cartList.count ++
    }
  }
}
</script>

<style scoped>
.cart-list-item {
  height: 120px;
  width: 100%;
  display: flex;
  padding: 0px 8px 0 8px;
  border-bottom: 1px solid #bbb;
}

.button {
  flex: 1;
}

.img {
  /* width: 100%; */
  flex: 2;
  text-align: center;
  display: flex;
  align-items: center;
}

.img img {
  height: 100px;
}

.item-info {
  flex: 6;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
}

.title,.desc {
  width: calc(100vw - 40vw);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.title {
  font-size: 18px;
  font-weight: 700;
}

.desc {  
  font-size: 14px;
}

.price-info {
  width: calc(100vw - 40vw);
  display: flex;
  justify-content: space-between;
}

.price-info span:nth-child(1) {
  color: red;
}

.price-info button {
  width: 22px;
  text-align: center;
}
</style>